﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MSBTC.WinForms;
using MSBTC.WinFormHelpers;
using MSBTC.ListWinForms;
using MSBTC.Model;
namespace MSBTC
{
    public partial class MDIParent : Form
    {
        FormHelpers helper = new FormHelpers();
        SessionHelper seshelp = new SessionHelper();
        private MdiClient ctlClient = new MdiClient();
        PMSContext dbcontext = new PMSContext();
        public string frmname;
       

        public MDIParent()
        {
            //ShowForms();
            InitializeComponent();
            //base.Controls.Add(this.userpanel);
        }

   
        //public Form MdiForm
        //{
        //    get
        //    {
        //        if (this.mdiForm == null)
        //        {
        //            this.mdiForm = new Form();
        //            /// set the hidden ctlClient field which is used to determine if the form is an MDI form
        //            System.Reflection.FieldInfo field = typeof(Form).GetField("userpanel", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
        //            field.SetValue(this.mdiForm, this.userpanel);
        //        }
        //        return this.mdiForm;
        //    }
        //}

        public void closeform()
        {
            
            if (userpanel.Controls.Count > 0)
            {
                foreach (Form aForm in this.userpanel.Controls)
                {
                    aForm.Close();
                }
            }
        }


        public string MDIContainer(string formname)
        {
            
            MainForm MForm = new MainForm();
            
            if (formname == null)
            {
                return null;
            }
            else
            {
             
                switch (formname)
                {
                    case "Login Form":
                        Login LForm = new Login();
                        LForm.MdiParent = this;
                        this.userpanel.Controls.Add(LForm);
                        //HideForms();
                        LForm.Show();
                        break;

                    case "Main Form":

                        MForm.MdiParent = this;
                        this.userpanel.Controls.Add(MForm);
                        MForm.Enabled = true;
                        //HideForms();
                        MForm.Show();
                        break;

                    #region ...
                    //case "Client Form":

                    //    CForm.MdiParent = this;
                    //    this.userpanel.Controls.Add(CForm);
                    //    //HideForms();
                    //    CForm.Show();
                    //    break;

                    //case "Supplier Form":

                    //    SForm.MdiParent = this;
                    //    this.userpanel.Controls.Add(SForm);
                    //    //HideForms();
                    //    SForm.Show();
                    //    break;

                    //case "Equipment Form":

                    //    EForm.MdiParent = this;
                    //    this.userpanel.Controls.Add(EForm);
                    //    //HideForms();
                    //    EForm.Show();
                    //    break;

                    //case "User Form":

                    //    UForm.MdiParent = this;
                    //    this.userpanel.Controls.Add(UForm);
                    //    //HideForms();
                    //    UForm.Show();
                    //    break;

                    //case "Delivery Receipt":

                    //    DRForm.MdiParent = this;
                    //    this.userpanel.Controls.Add(DRForm);
                    //    //HideForms();
                    //    DRForm.Show();
                    //    break;

                    //case "Project Information":

                    //    PIForm.MdiParent = this;
                    //    this.userpanel.Controls.Add(PIForm);
                    //    //HideForms();
                    //    PIForm.Show();
                    //    break;

                    //case "Category Form":

                    //    CatForm.MdiParent = this;
                    //    this.userpanel.Controls.Add(CatForm);
                    //    //HideForms();
                    //    CatForm.Show();
                    //    break;

                    //case "Labor Form":

                    //    LbForm.MdiParent = this;
                    //    this.userpanel.Controls.Add(LbForm);
                    //    //HideForms();
                    //    LbForm.Show();
                    //    break;

                    //case "Damage Form":

                    //    DForm.MdiParent = this;
                    //    this.userpanel.Controls.Add(DForm);
                    //    //HideForms();
                    //    DForm.Show();
                    //    break;

                    //case "Material Form":

                    //    MtForm.MdiParent = this;
                    //    this.userpanel.Controls.Add(MtForm);
                    //   // HideForms();
                    //    MtForm.Show();
                    //    break;

                    //case "PMS Form":
                    //    PMSForm.MdiParent = this;
                    //    this.userpanel.Controls.Add(PMSForm);
                    //    PMSForm.Show();
                    //    break;
                    #endregion
                }
                frmname = formname;
                return frmname;
            }
        
        }

        private void MDIParent_Load(object sender, EventArgs e)
        {
                    
        }

        #region hover

        private void pbLabor_MouseHover(object sender, EventArgs e)
        {
            pbLabor.Cursor = Cursors.Hand;
        }

        private void pbUser_MouseHover(object sender, EventArgs e)
        {
            pbUser.Cursor = Cursors.Hand;
        }

        private void pbProject_MouseHover(object sender, EventArgs e)
        {
            pbProject.Cursor = Cursors.Hand;
        }

        private void pbMaterials_MouseHover(object sender, EventArgs e)
        {
            pbMaterials.Cursor = Cursors.Hand;
        }

        private void pbEquip_MouseHover(object sender, EventArgs e)
        {
            pbEquip.Cursor = Cursors.Hand;
        }

        private void pbSupplier_MouseHover(object sender, EventArgs e)
        {
            pbSupplier.Cursor = Cursors.Hand;
        }

        private void pbClient_MouseHover(object sender, EventArgs e)
        {
            pbClient.Cursor = Cursors.Hand;
        }

        private void pbDR_MouseHover(object sender, EventArgs e)
        {
            pbDR.Cursor = Cursors.Hand;
        }
        #endregion
        #region event click
        private void Exit_Click(object sender, EventArgs e)
        {
            DialogResult frmclose = MessageBox.Show("Do you really want to exit?", "Closing", MessageBoxButtons.YesNo);
            if (frmclose == DialogResult.Yes)
            {
                Application.Exit();
            }
        }

        private void pbClient_Click(object sender, EventArgs e)
        {
            string date = DateTime.Today.ToShortDateString();
            string ip = seshelp.Session_GetIP();
            var ses = (from sess in dbcontext.Sessions
                       where sess.IPAddress == ip && sess.Date_Logout == null
                       && sess.Date_Created == date
                       select sess).SingleOrDefault();

            if (ses != null)
            {
                ClientListForm CList = new ClientListForm();
                CList.Show();
            }
            else
            {
                MessageBox.Show("Please Login", "Login", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        private void pbSupplier_Click(object sender, EventArgs e)
        {
            string date = DateTime.Today.ToShortDateString();
            string ip = seshelp.Session_GetIP();
            var ses = (from sess in dbcontext.Sessions
                       where sess.IPAddress == ip && sess.Date_Logout == null
                       && sess.Date_Created == date
                       select sess).SingleOrDefault();

            if (ses != null)
            {
                SupplierListForm SList = new SupplierListForm();
                SList.Show();
            }
            else
            {
                MessageBox.Show("Please Login", "Login", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        private void pbEquip_Click(object sender, EventArgs e)
        {
            string date = DateTime.Today.ToShortDateString();
            string ip = seshelp.Session_GetIP();
            var ses = (from sess in dbcontext.Sessions
                       where sess.IPAddress == ip && sess.Date_Logout == null
                       && sess.Date_Created == date
                       select sess).SingleOrDefault();
            if (ses != null)
            {
                EquipmentListForm EList = new EquipmentListForm();
                EList.Show();
            }
            else
            {
                MessageBox.Show("Please Login", "Login", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        private void pbMaterials_Click(object sender, EventArgs e)
        {
            string date = DateTime.Today.ToShortDateString();
            string ip = seshelp.Session_GetIP();
            var ses = (from sess in dbcontext.Sessions
                       where sess.IPAddress == ip && sess.Date_Logout == null
                       && sess.Date_Created == date
                       select sess).SingleOrDefault();
            if (ses != null)
            {
                MaterialsListForm MList = new MaterialsListForm();
                MList.Show();
            }
            else
            {
                MessageBox.Show("Please Login", "Login", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        private void pbProject_Click(object sender, EventArgs e)
        {
            string date = DateTime.Today.ToShortDateString();
            string ip = seshelp.Session_GetIP();
            var ses = (from sess in dbcontext.Sessions
                       where sess.IPAddress == ip && sess.Date_Logout == null
                       && sess.Date_Created == date
                       select sess).SingleOrDefault();
            if (ses != null)
            {
                ProjectListForm PList = new ProjectListForm();
                PList.Show();
            }
            else
            {
                MessageBox.Show("Please Login", "Login", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        private void pbUser_Click(object sender, EventArgs e)
        {
            string date = DateTime.Today.ToShortDateString();
            string ip = seshelp.Session_GetIP();
            var ses = (from sess in dbcontext.Sessions
                       where sess.IPAddress == ip && sess.Date_Logout == null
                       && sess.Date_Created == date
                       select sess).SingleOrDefault();
            if (ses != null)
            {
                UserListForm UList = new UserListForm();
                UList.Show();
            }
            else
            {
                MessageBox.Show("Please Login", "Login", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        private void pbDR_Click(object sender, EventArgs e)
        {
            string date = DateTime.Today.ToShortDateString();
            string ip = seshelp.Session_GetIP();
            var ses = (from sess in dbcontext.Sessions
                       where sess.IPAddress == ip && sess.Date_Logout == null
                       && sess.Date_Created == date
                       select sess).SingleOrDefault();
            if (ses != null)
            {
                DeliveryListForm DRList = new DeliveryListForm();
                DRList.Show();
            }
            else
            {
                MessageBox.Show("Please Login", "Login", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        private void pbLabor_Click(object sender, EventArgs e)
        {
            string date = DateTime.Today.ToShortDateString();
            string ip = seshelp.Session_GetIP();
            var ses = (from sess in dbcontext.Sessions
                       where sess.IPAddress == ip && sess.Date_Logout == null
                       && sess.Date_Created == date
                       select sess).SingleOrDefault();
            if (ses != null)
            {
                LaborerListForm LList = new LaborerListForm();
                LList.Show();
            }
            else
            {
                MessageBox.Show("Please Login", "Login", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        #endregion
    }
}
